from tool.vector import Vector


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y


class Rectangle:
    def __init__(self, xmin:float, xmax:float, ymin:float, ymax:float):
        self.xmin = xmin
        self.xmax = xmax
        self.ymin = ymin
        self.ymax = ymax


def closest_edge(point:Vector, rectangle:Rectangle):
    dist_left = point.x - rectangle.xmin
    dist_right = rectangle.xmax - point.x
    dist_top = rectangle.ymax - point.y
    dist_bottom = point.y - rectangle.ymin
    min_distance = min(dist_left, dist_right, dist_top, dist_bottom)
    if min_distance == dist_left:
        return "left"
    elif min_distance == dist_right:
        return "right"
    elif min_distance == dist_top:
        return "top"
    elif min_distance == dist_bottom:
        return "bottom"


# 示例用法
if __name__ == "__main__":
    point = Point(5.0, 2.0)
    rectangle = Rectangle(1.0, 5.0, 2.0, 4.0)

    closest_side = closest_edge(point, rectangle)
    print(f"Closest to {closest_side} side")
